<template>
	<!-- 首页灵活用工详情页组件 -->
	<view class="main">
		<u-sticky>
		<view class="search">
			<u-search :show-action='true' placeholder="请输入工作/工种名称" @custom="search" v-model="keyword"></u-search>
		</view>
		</u-sticky>
		
		<view class="hotWork">
			<view style="margin-top: 150rpx;" v-if='lists.length==0'>
				<u-empty text="暂无数据" mode="list"></u-empty>
			</view>
			
			<view class="workItem" v-for="(item,index) in lists" :key="index" @click="goDetil(item.id,type)">
				<view class="header">
					<text class="name">{{item.work_name}}</text>
					<text class="money">{{item.wages.replace(',', '')}}</text>
				</view>
				<view class="center">
					<view class="tags">
						<view class="tagItem">{{item.create_type}}</view>
						<view class="tagItem">{{item.settlement}}</view>
						<view class="tagItem" v-if="item.info_type=='招工'">{{item.need_num}}人</view>
					</view>
					<view class="time">
						{{item.add_time.substring(0,10)}}
					</view>
				</view>
				<view class="footer">
					<view class="address">{{item.province+item.city+item.area+item.address}}</view>
				<view class="add1">
					{{ item.juli<1000?(item.juli || '')+'m':((item.juli/1000).toFixed(2) || '')+'km'}}
				</view>
				</view>
				<view class="operate">					
					<u-button type="warning" class="fully" size="mini" @click="Fully(item.id)">已招满</u-button>
					<u-button type="primary" class="edi" size="mini" @click="modify(item.id,type,item.create_type)">修改</u-button>
					<!-- <u-button type="error" class="del" size="mini" @click="Delete(item.id)" >删除</u-button>					 -->
				</view>
				
				
			</view>
			<view style="margin-top: 30rpx;">
				<u-loadmore style="margin-top: 30rpx;" :status="status" />
			</view>
			
			
		</view>

	</view>
</template>

<script>
	import api from '../../../../api/routes.js'
	export default {
		data() {
			return {
				page: 1,
				limit: 5,
				status: "loadmore",
				lists: [],
				// 拿到的数据总条数
				total: 0,
				//判断是否发送请求的条件
				load: false,

				keyword: '',

				type:'热门',
				
			};
		},
		onLoad(options) {
			this.type = options.type
			let that = this
				wx.getLocation({
				 type: 'wgs84',
				 success (res) {
				   that.lat = res.latitude
				   that.lgt= res.longitude
				   that.getList()
				 }
				})
			// uni.$on('updateData', async function () {
			// 	console.log('xiozitonx');
			// 	this.lists=[]
			// 	that.getList()
			     
			// })
		},
		onReachBottom() {
			if (this.status === "loadmore") {
				this.loadmore();
			}
		},
		methods: {
			goDetil(id,type){
				uni.navigateTo({
					url: '/package/pages/searchJob/other/detils?id='+id+'&type='+type,
				});
				console.log(id,type,20200);
				
				
			},
			search(val) {
				this.load = false;
				this.page = 1
				this.limit = 5
				this.status = 'loadmore'
				this.lists = []
				this.getList()
			},
			loadmore() {
				this.page++;
				this.getList();
			},
			async getList() {
				wx.showLoading()
				// 判断当前是否在请求，如果为true正在请求数据，就让他返回空，如果为false没在请求，就让它开始请求数据
				if (this.load) {
					return;
				}
				this.load = true;
				// 请求数据时，状态改为加载中状态
				this.status = "loading";
				const res = await this.$myRequest({
					url: api.lgInfoPageList,
					method: "POST",
					data: {
						page: this.page,
						limit: this.limit,
						"orderSort": 1, //排序方式:1-热门,2-附近
						"key": this.keyword, //搜索关键词,
						"wages": "", //薪资
						"settlement": "", // 结算方式
						"mbId": uni.getStorageSync("member").mbId, //用户ID, ~~~~传这个值时,代表查询我发布的 ,大多数都不传
						"infoType": this.type, //类型:招工  / 求职  (必传)
						"lgt":this.lgt,
						"lat":this.lat,
					},
				});
				console.log(res,"是否重复11")
				this.load = false;
				if (res.data.code == 0) {
					// this.lists = res.data.page.list
					this.total = res.data.page.totalCount;
					this.lists = [...this.lists, ...res.data.page.list];
					this.ismore();
					setTimeout(() => {
						wx.hideLoading()
					}, 2000)
				} else {
					wx.showToast({
						title: '查询失败',
						icon: 'none'
					})
				}
				
			},
			ismore() {
				if (this.total === this.lists.length) {
					this.status = "nomore";
				} else {
					this.status = "loadmore";
				}
			},
			change(val){
				this.type = val
				this.search()
			},
			bmjl(){
				uni.navigateTo({
					url: '/package/pages/searchJob/other/baomingjilu',
				});
			},
			goFabu(){
				uni.navigateTo({
					url: '/package/pages/searchJob/other/addInfo',
				});
			},
			lgRegister() {
				console.log("林工登记！！！");
				uni.navigateTo({
					url: '/package/pages/components/lingGonRegister',
				});
			},
			async Fully(id){
				console.log(id,"已招满");
				let that=this;
				wx.showModal({
				  title: '提示',
				  content: '你确定设置已招满？',
				  success (res) {
				    if (res.confirm) {
				      console.log('用户点击确定')
					  that.$myRequest({
						  url: api.fullyRecruited,
						  	  	method: "GET",
						  	  	data: {
						  	  		id
						  	  	},
					  }).then(res=>{
						  if(res.data.code==0){
						  	wx.showToast({
						  		title: res.data.msg,
						  		icon: 'none'
						  	})				
						  	setTimeout(() => {
						  		wx.navigateBack({
						  		  delta: 1
						  		})
						  		wx.hideLoading()
						  	}, 1500)
						  }
					  })
					  
				    } else if (res.cancel) {
				      console.log('用户点击取消')
				    }
				  }
				})
				
				
				
				
				
				
				
				
				
				
				
				
				// const res = await this.$myRequest({
				// 	  	url: api.fullyRecruited,
				// 	  	method: "GET",
				// 	  	data: {
				// 	  		id
				// 	  	},
				// 	  });
				// console.log(res,45445);
				// if(res.data.code==0){
				// 	wx.showToast({
				// 		title: res.data.msg,
				// 		icon: 'none'
				// 	})				
				// 	setTimeout(() => {
				// 		wx.navigateBack({
				// 		  delta: 1
				// 		})
				// 		wx.hideLoading()
				// 	}, 1500)
				// }
				
			},
			
			
			modify(id,type,create_type){
				console.log(id,type,create_type,"111修改");
				if(type=="求职"){
					uni.navigateTo({
						url: '/package/pages/searchJob/other/addInfoDetil?id='+id+'&type=修改'+'&type1=求职',
					});
				}else{
					uni.navigateTo({
						url: '/package/pages/searchJob/other/addInfoDetil1?id='+id+'&type=修改'+'&create_type='+create_type+'&type1=招工',
					});
				}
				
			},
			async Delete(id){
				console.log(id,"删除");
				const res = await this.$myRequest({
					  	url: api.lgDelete,
					  	method: "GET",
					  	data: {
					  		id
					  	},
					  });
				console.log(res,55656);
				if(res.data.code==0){
					wx.showToast({
						title: res.data.msg,
						icon: 'none'
					})				
					setTimeout(() => {
						wx.navigateBack({
						  delta: 1
						})
						wx.hideLoading()
					}, 1500)
				}
				
				// this.getList()
				// wx.showModal({
				//   title: '提示',
				//   content: '你确定删除吗？',
				//  async success (res) {
				//     if (res.confirm) {
				//       console.log('确定')
				// 	  const res = await this.$myRequest({
				// 	  	url: api.lgDelete,
				// 	  	method: "GET",
				// 	  	data: {
				// 	  		id
				// 	  	},
				// 	  });
				// 	  console.log(res,55656);
				//     } else if (res.cancel) {
				//       console.log('取消')
				//     }
				//   }
				// })
			},
			
		},
	};
</script>

<!-- <style>
/* #ifndef H5 */
page {
  height: 100%;
  background-color: #f2f2f2;
}

/* #endif */
</style> -->

<style lang="scss" scoped>
	.main {
		background: #ffffff;
	}
	.search{
		background: white;
		padding-top: 10rpx;
		padding-bottom: 10rpx;
		padding-left: 10rpx;
	}
	.register {
		height: 180rpx;
		background: white;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		padding-top: 20rpx;
		padding-bottom: 20rpx;
		.item_three{
			width: 25%;
			height: 120rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			color: #909399;
			font-size: 24rpx;
			flex-direction: column;
			image{
				// width: 128rpx;
				// height: 128rpx;
				border-radius: 10px;
				// height: 80rpx;
			}
		}

	}
	.hotWork{
		background: white;
		.title{
			font-family: Arial, Helvetica, sans-serif;
			margin-left: 3%;
			display: flex;
			color: #909399;
			justify-content: space-between;
			.tabs{
				margin-right: 30rpx;
				.line{
					width: 30rpx;
					height: 4px;
					background: #1684fd;
					// background: #000088;
					margin-left: 15rpx;
					border-radius: 0 0 10rpx 10rpx;
				}
			}
			.active{
				color: #333;
				font-weight: bold;
			}
			.left{
				display: flex;
			}
			.right{
				margin-right: 3%;
			}

		}
		.workItem{
			width: 94%;
			margin-left: 3%;
			// height: 240rpx;
			border-radius: 6px;
			box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
			margin-top: 20rpx;
			.header{
				height:90rpx;
				.name{
					color: #333;
					font-size: 30rpx;
					font-weight: 500;
					font-family: Arial, Helvetica, sans-serif;
				}
				.money{
					color: orange;
					font-size: 28rpx;
					font-weight: 500;
					font-family: Arial, Helvetica, sans-serif;
				}
			}
			.center{
				height: 75rpx;
				border-bottom: 1px solid #E4E7ED;
				.time{
					color: #909399;
					font-size: 24rpx;
					font-family: Arial, Helvetica, sans-serif;
				}
				.tags{
					display: flex;
					.tagItem{
						font-size: 24rpx;
						margin-right: 15rpx;
						padding:4rpx 10rpx 4rpx 10rpx;
						border-radius: 2px;
						background: #DBF1E1;
						color: #19BE6B;
					}

				}
			}

			.footer{
				height:75rpx;
				.address{
					
					color: #909399;
					font-size: 24rpx;
					font-family: Arial, Helvetica, sans-serif;
					width: 84%;
				}
				.add1{
					color: #C0C4CC;
					font-size: 24rpx;
					font-family: Arial, Helvetica, sans-serif;
				}
			}
			.header,.center,.footer{
				display: flex;
				align-items: center;
				justify-content: space-between;
				width: 96%;
				margin-left: 2%;
			}
		}
	}
	.operate{
		display: flex;
		justify-content: flex-end;
		padding: 0 6px 6px 0;
		// .fully, .edi, .del{
		// 	width: 40px;
		// 	height: 30px;
			
		// }
		.fully{
			margin-right: 10px;
		}
	}
</style>
